


        const response = await axios.get(ACCESS_TOKEN_URL);
         console.log('获取 access_token 的响应:', response.data);
        return response.data.access_token;
    } catch (error) {
        console.error('获取 access_token 失败:', error.response? error.response.data : error.message);
        return null;
    }
}

async function getChatResponse(text) {
    const accessToken = await getAccessToken();
    if (!accessToken) return null;
    try {
        const response = await axios.post(
            `${CHAT_API_URL}?access_token=${accessToken}`,
            {
                messages: [
                    {
                        role: 'user',
                        content: text
                    }
                ]
            },
            {
                headers: {
                    'Content-Type': 'application/json'
                }
            }
        );
        return response.data.choices[0].message.content;
    } catch (error) {
        console.error('发送消息失败:', error);
        return null;
    }
}

// 示例调用
const inputText = '你好';
getChatResponse(inputText).then((response) => {
    if (response) {
        console.log('模型回复:', response);
    }
});

